<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <h3>普通价格：{{price}}</h3>
        <h3>会员价格：{{memberPrice}}</h3>
        <h3>会员价格：{{vipPrice}}</h3>
    </div>
</body>
<script src="js/vue.js"></script>
<script>
    const app = Vue.createApp({
        data(){
            return {
                price: 5,
                vipPrice: 0,
            }
        },
        // 计算属性中不能做异步操作
        computed: {
            memberPrice() {
                return this.price * 0.5;
            }
        },
        // 侦听器，侦听 data 中值的变化
        // watch 中可以做异步操作
        watch:{
            price(newValue, oldValue){
                console.log("价格发生变化", newValue, oldValue);
                this.vipPrice = newValue * 0.4;
            }
        }
    }).mount("#app");
</script>
</html>